<template>
  <div class="index full">
    <div id="topbar" class="full fb">
      <!-- <div id="topbarLogo" v-show="false">
        <img id="topbarLogoImg" src="../../assets/images/login/logo.jpg" alt>
      </div>
      <div id="topbarLogoName">{{ appName }}</div>
      <div id="topbarCon" class="fb1"></div>
      <partBtns id="topbarBtns"/>-->
      <div class="header-content">
        <div class="left">
          <i class="login-logo"></i>
          <span class="line"></span>
          <span class="login-name">{{ appName }}</span>
        </div>
        <!-- <div v-for='it in menus' :key='it.id' style='cursor:pointer' :style='{color:it.name == curMenu.name?"#ffd04b":"white"}' @click='nameClick(it)'>{{it.name}}</div> -->
        <partBtns id="topbarBtns" />
      </div>
    </div>
    <part-menu id="menu" class="full" :menus="menus" :isCollapse="isCollapse" :nowTab="nowTab" />
    <!-- <part-menu id="menu" class="full" ref='menuChild' :menus="curMenu.children" :isCollapse="isCollapse" :nowTab="nowTab" /> -->
    <part-tabs id="part-tabs" @isOpen="isOpen" :class="{'part-collapse':isCollapse}" />
    <div id="con" class="full" :class="{'part-collapse':isCollapse}">
      <!--      <keep-alive :include="includedComponents">-->
      <router-view />
      <!--      </keep-alive>-->
    </div>
  </div>
</template>

<script>
import partMenu from "./parts/Menu/";
import partTabs from "./parts/Tabs";
import partBtns from "./parts/Btns";
import { mapGetters } from "vuex";

export default {
  name: "Index",
  components: {
    partMenu,
    partTabs,
    partBtns,
  },
  computed: {
    ...mapGetters(["tabs", "nowTab", "menus"]),
    includedComponents: function() {
      // 首页默认缓存
      var comps = [PUZZLE_CONFIG.pageHome ? PUZZLE_CONFIG.pageHome : "Home"];
      // 根据路由地址处理其他tab
      for (var i in this.tabs) {
        if (this.tabs[i]) {
          comps.push(this.tabs[i].id);
        }
      }
      return comps;
    },
  },
  data() {
    return {
      isCollapse: false,
      appName: PUZZLE_CONFIG.appName,
      appVersion: PUZZLE_CONFIG.appVersion,
      curMenu: JSON.parse(sessionStorage.getItem("curMenu")),
    };
  },
  created() {
    this.$nextTick(() => {
      this.$bus.$emit("gitMenuBus");
    });
  },
  mounted() {
    // this.nameClick(this.curMenu || this.menus[0]);
    this.setMenus()
  },
  methods: {
    setMenus() {
      window.sessionStorage.setItem('menus', JSON.stringify(this.menus))
    },
    isOpen(data) {
      this.isCollapse = data;
    },
    nameClick(it) {
      this.curMenu = it;
      sessionStorage.setItem("curMenu", JSON.stringify(it));
      // this.$refs.menuChild.$refs.menu[0].clickMenu();
    },
  },
};
</script>

<style lang="less">
@import "~@frames/dashboard/style/var";

.index {
  background: @bg;
}

#topbar {
  @light-primary: lighten(@primary, 10%);
  @dark-primary: darken(@primary, 5%);
  height: @topBarH;
  bottom: auto;
  z-index: 5;

  background: @primary;
  background: linear-gradient(135deg, @dark-primary, @light-primary);
  

  &Logo {
    @aniTime: 0.3s;
    display: inline-block;
    width: @topBarH;
    height: @topBarH;
    padding: 10px;

    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background @aniTime;

    &Img {
      filter: grayscale(1) brightness(2);
      width: 100%;
      transition: filter @aniTime;
    }

    &:hover {
      background: #fff;
      #topbarLogoImg {
        filter: grayscale(0) brightness(1);
      }
    }
  }

  &LogoName {
    padding: 0 10px;
    font-size: 19px;
    font-weight: bold;
    color: #fff;
    letter-spacing: 3px;
    text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.1);
  }

  .header-content {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left {
      display: flex;
      align-items: center;
      padding-left: 20px;
    }
    .login-logo {
      display: inline-block;
      width: 43px;
      height: 43px;
      background: url(../../assets/images/login/login_logo.png) no-repeat;
      background-size: cover;
    }
    .line {
      display: inline-block;
      width: 1px;
      background: #fff;
      height: 26px;
      margin: 0 10px;
    }
    .login-name {
      font-size: 20px;
      color: #fff;
      font-weight: bold;
    }
  }
}

#menu {
  top: @topBarH;
  width: @menuBarW;
  z-index: 4;

  background: #fff;
  box-shadow: 2px 0px 5px 0px rgba(0, 0, 0, 0.05);
  transition: width 0.3s;
}

#part-tabs {
  top: @topBarH;
  left: @menuBarW;
  height: @TabsH;

  z-index: 3;

  background: #fff;
  box-shadow: 0 2px 5px 0px rgba(0, 0, 0, 0.05);
}

#con {
  top: @topBarH + @TabsH;
  left: @menuBarW;
  z-index: 1;
  overflow: auto;
  overflow: overlay;
}
.part-collapse {
  left: 64px !important;
}
</style>
